;--------------------------------------------------------
; File Created by SDCC : free open source ANSI-C Compiler
; Version 3.0.0 #6037 (Apr 28 2011) (Mac OS X ppc)
; This file was generated Wed May 11 03:52:29 2011
;--------------------------------------------------------
; PIC16 port for the Microchip 16-bit core micros
;--------------------------------------------------------

	.ident "SDCC version 3.0.0 #6037 [pic16 port]"
	.file	"hamming.c"
	list	p=18f2550

	radix dec

;--------------------------------------------------------
; public variables in this module
;--------------------------------------------------------
	global _HammingMatrixEncode
	global _HammingTableEncode
	global _HammingMatrixDecode
	global _HammingTableDecode
	global _HammingPackedTableDecode
	global _SumBitsModulo2
	global _g
	global _gT
	global _hammingCodes
	global _h
	global _syndromeMask
	global _hammingDecodeValues
	global _hammingPackedDecodeValues

;--------------------------------------------------------
; extern variables in this module
;--------------------------------------------------------
	extern _stdin
	extern _stdout
;--------------------------------------------------------
;	Equates to used internal registers
;--------------------------------------------------------
STATUS	equ	0xfd8
WREG	equ	0xfe8
TBLPTRL	equ	0xff6
TBLPTRH	equ	0xff7
TBLPTRU	equ	0xff8
TABLAT	equ	0xff5
FSR1L	equ	0xfe1
FSR2L	equ	0xfd9
POSTDEC1	equ	0xfe5
PREINC1	equ	0xfe4
PLUSW2	equ	0xfdb


; Internal registers
.registers	udata_ovr	0x0000
r0x00	res	1
r0x01	res	1
r0x02	res	1
r0x03	res	1
r0x04	res	1
r0x05	res	1

;--------------------------------------------------------
; global & static initialisations
;--------------------------------------------------------
; I code from now on!
; ; Starting pCode block
S_hamming__HammingPackedTableDecode	code
_HammingPackedTableDecode:
	.line	321; hamming.c	unsigned char HammingPackedTableDecode(unsigned char hamming_code)
	MOVFF	FSR2L, POSTDEC1
	MOVFF	FSR1L, FSR2L
	MOVFF	r0x00, POSTDEC1
	MOVFF	r0x01, POSTDEC1
	MOVFF	r0x02, POSTDEC1
	MOVFF	r0x03, POSTDEC1
	MOVLW	0x02
	MOVFF	PLUSW2, r0x00
	.line	325; hamming.c	decoded = hammingPackedDecodeValues[hamming_code / 2];
	RRNCF	r0x00, W
	ANDLW	0x7f
	MOVWF	r0x01
	CLRF	r0x02
	CLRF	r0x03
	MOVLW	LOW(_hammingPackedDecodeValues)
	ADDWF	r0x01, F
	MOVLW	HIGH(_hammingPackedDecodeValues)
	ADDWFC	r0x02, F
	MOVLW	UPPER(_hammingPackedDecodeValues)
	ADDWFC	r0x03, F
	MOVFF	r0x01, TBLPTRL
	MOVFF	r0x02, TBLPTRH
	MOVFF	r0x03, TBLPTRU
	TBLRD*+	
	MOVFF	TABLAT, r0x01
	.line	327; hamming.c	if (hamming_code % 2)
	BTFSS	r0x00, 0
	BRA	_00167_DS_
	.line	330; hamming.c	decoded &= (0xFF >> DATA_BITS);
	MOVLW	0x0f
	ANDWF	r0x01, F
	BRA	_00168_DS_
_00167_DS_:
	.line	335; hamming.c	decoded >>= DATA_BITS;
	SWAPF	r0x01, W
	ANDLW	0x0f
	MOVWF	r0x01
_00168_DS_:
	.line	338; hamming.c	return decoded;
	MOVF	r0x01, W
	MOVFF	PREINC1, r0x03
	MOVFF	PREINC1, r0x02
	MOVFF	PREINC1, r0x01
	MOVFF	PREINC1, r0x00
	MOVFF	PREINC1, FSR2L
	RETURN	

; ; Starting pCode block
S_hamming__HammingTableDecode	code
_HammingTableDecode:
	.line	302; hamming.c	unsigned char HammingTableDecode(unsigned char hamming_code)
	MOVFF	FSR2L, POSTDEC1
	MOVFF	FSR1L, FSR2L
	MOVFF	r0x00, POSTDEC1
	MOVFF	r0x01, POSTDEC1
	MOVFF	r0x02, POSTDEC1
	MOVLW	0x02
	MOVFF	PLUSW2, r0x00
	.line	304; hamming.c	return hammingDecodeValues[hamming_code];
	CLRF	r0x01
	CLRF	r0x02
	MOVLW	LOW(_hammingDecodeValues)
	ADDWF	r0x00, F
	MOVLW	HIGH(_hammingDecodeValues)
	ADDWFC	r0x01, F
	MOVLW	UPPER(_hammingDecodeValues)
	ADDWFC	r0x02, F
	MOVFF	r0x00, TBLPTRL
	MOVFF	r0x01, TBLPTRH
	MOVFF	r0x02, TBLPTRU
	TBLRD*+	
	MOVFF	TABLAT, r0x00
	MOVF	r0x00, W
	MOVFF	PREINC1, r0x02
	MOVFF	PREINC1, r0x01
	MOVFF	PREINC1, r0x00
	MOVFF	PREINC1, FSR2L
	RETURN	

; ; Starting pCode block
S_hamming__HammingMatrixDecode	code
_HammingMatrixDecode:
	.line	265; hamming.c	unsigned char HammingMatrixDecode(unsigned char hamming_code)
	MOVFF	FSR2L, POSTDEC1
	MOVFF	FSR1L, FSR2L
	MOVFF	r0x00, POSTDEC1
	MOVFF	r0x01, POSTDEC1
	MOVFF	r0x02, POSTDEC1
	MOVFF	r0x03, POSTDEC1
	MOVFF	r0x04, POSTDEC1
	MOVFF	r0x05, POSTDEC1
	MOVLW	0x02
	MOVFF	PLUSW2, r0x00
	.line	270; hamming.c	syndromeVal = 0;
	CLRF	r0x01
	.line	272; hamming.c	for (i = 0; i < PARITY_BITS; i++)
	CLRF	r0x02
_00146_DS_:
	MOVLW	0x03
	SUBWF	r0x02, W
	BC	_00149_DS_
	.line	274; hamming.c	syndromeVal <<= 1;
	BCF	STATUS, 0
	RLCF	r0x01, F
	.line	277; hamming.c	syndromeColBits = (h[i] & hamming_code);
	MOVLW	LOW(_h)
	ADDWF	r0x02, W
	MOVWF	r0x03
	CLRF	r0x04
	MOVLW	HIGH(_h)
	ADDWFC	r0x04, F
	CLRF	r0x05
	MOVLW	UPPER(_h)
	ADDWFC	r0x05, F
	MOVFF	r0x03, TBLPTRL
	MOVFF	r0x04, TBLPTRH
	MOVFF	r0x05, TBLPTRU
	TBLRD*+	
	MOVFF	TABLAT, r0x03
	MOVF	r0x00, W
	ANDWF	r0x03, F
	.line	280; hamming.c	if (SumBitsModulo2(syndromeColBits))
	MOVF	r0x03, W
	MOVWF	POSTDEC1
	CALL	_SumBitsModulo2
	MOVWF	r0x03
	INCF	FSR1L, F
	MOVF	r0x03, W
	BZ	_00148_DS_
	.line	282; hamming.c	syndromeVal |= 1;
	BSF	r0x01, 0
_00148_DS_:
	.line	272; hamming.c	for (i = 0; i < PARITY_BITS; i++)
	INCF	r0x02, F
	BRA	_00146_DS_
_00149_DS_:
	.line	287; hamming.c	return ((hamming_code ^ syndromeMask[syndromeVal]) & (0xFF >> DATA_BITS));
	CLRF	r0x02
	CLRF	r0x03
	MOVLW	LOW(_syndromeMask)
	ADDWF	r0x01, F
	MOVLW	HIGH(_syndromeMask)
	ADDWFC	r0x02, F
	MOVLW	UPPER(_syndromeMask)
	ADDWFC	r0x03, F
	MOVFF	r0x01, TBLPTRL
	MOVFF	r0x02, TBLPTRH
	MOVFF	r0x03, TBLPTRU
	TBLRD*+	
	MOVFF	TABLAT, r0x01
	MOVF	r0x01, W
	XORWF	r0x00, F
	MOVLW	0x0f
	ANDWF	r0x00, F
	MOVF	r0x00, W
	MOVFF	PREINC1, r0x05
	MOVFF	PREINC1, r0x04
	MOVFF	PREINC1, r0x03
	MOVFF	PREINC1, r0x02
	MOVFF	PREINC1, r0x01
	MOVFF	PREINC1, r0x00
	MOVFF	PREINC1, FSR2L
	RETURN	

; ; Starting pCode block
S_hamming__HammingTableEncode	code
_HammingTableEncode:
	.line	245; hamming.c	unsigned char HammingTableEncode(unsigned char s)
	MOVFF	FSR2L, POSTDEC1
	MOVFF	FSR1L, FSR2L
	MOVFF	r0x00, POSTDEC1
	MOVFF	r0x01, POSTDEC1
	MOVFF	r0x02, POSTDEC1
	MOVLW	0x02
	MOVFF	PLUSW2, r0x00
	.line	247; hamming.c	return hammingCodes[s];
	CLRF	r0x01
	CLRF	r0x02
	MOVLW	LOW(_hammingCodes)
	ADDWF	r0x00, F
	MOVLW	HIGH(_hammingCodes)
	ADDWFC	r0x01, F
	MOVLW	UPPER(_hammingCodes)
	ADDWFC	r0x02, F
	MOVFF	r0x00, TBLPTRL
	MOVFF	r0x01, TBLPTRH
	MOVFF	r0x02, TBLPTRU
	TBLRD*+	
	MOVFF	TABLAT, r0x00
	MOVF	r0x00, W
	MOVFF	PREINC1, r0x02
	MOVFF	PREINC1, r0x01
	MOVFF	PREINC1, r0x00
	MOVFF	PREINC1, FSR2L
	RETURN	

; ; Starting pCode block
S_hamming__HammingMatrixEncode	code
_HammingMatrixEncode:
	.line	212; hamming.c	unsigned char HammingMatrixEncode(unsigned char s)
	MOVFF	FSR2L, POSTDEC1
	MOVFF	FSR1L, FSR2L
	MOVFF	r0x00, POSTDEC1
	MOVFF	r0x01, POSTDEC1
	MOVFF	r0x02, POSTDEC1
	MOVFF	r0x03, POSTDEC1
	MOVFF	r0x04, POSTDEC1
	MOVFF	r0x05, POSTDEC1
	MOVLW	0x02
	MOVFF	PLUSW2, r0x00
	.line	217; hamming.c	hamming_code = 0;
	CLRF	r0x01
	.line	219; hamming.c	for (i = 0; i < CODE_BITS; i++)
	CLRF	r0x02
_00124_DS_:
	MOVLW	0x07
	SUBWF	r0x02, W
	BC	_00127_DS_
	.line	221; hamming.c	hamming_code <<= 1;     /* hamming_code bits are accumlated from right to left */
	BCF	STATUS, 0
	RLCF	r0x01, F
	.line	224; hamming.c	rowBits = (gT[i] & s);       /* mod 2 multiplication of vectors */
	MOVLW	LOW(_gT)
	ADDWF	r0x02, W
	MOVWF	r0x03
	CLRF	r0x04
	MOVLW	HIGH(_gT)
	ADDWFC	r0x04, F
	CLRF	r0x05
	MOVLW	UPPER(_gT)
	ADDWFC	r0x05, F
	MOVFF	r0x03, TBLPTRL
	MOVFF	r0x04, TBLPTRH
	MOVFF	r0x05, TBLPTRU
	TBLRD*+	
	MOVFF	TABLAT, r0x03
	MOVF	r0x00, W
	ANDWF	r0x03, F
	.line	227; hamming.c	if (SumBitsModulo2(rowBits))
	MOVF	r0x03, W
	MOVWF	POSTDEC1
	CALL	_SumBitsModulo2
	MOVWF	r0x03
	INCF	FSR1L, F
	MOVF	r0x03, W
	BZ	_00126_DS_
	.line	229; hamming.c	hamming_code |= 1;
	BSF	r0x01, 0
_00126_DS_:
	.line	219; hamming.c	for (i = 0; i < CODE_BITS; i++)
	INCF	r0x02, F
	BRA	_00124_DS_
_00127_DS_:
	.line	233; hamming.c	return hamming_code;
	MOVF	r0x01, W
	MOVFF	PREINC1, r0x05
	MOVFF	PREINC1, r0x04
	MOVFF	PREINC1, r0x03
	MOVFF	PREINC1, r0x02
	MOVFF	PREINC1, r0x01
	MOVFF	PREINC1, r0x00
	MOVFF	PREINC1, FSR2L
	RETURN	

; ; Starting pCode block
S_hamming__SumBitsModulo2	code
_SumBitsModulo2:
	.line	184; hamming.c	unsigned char SumBitsModulo2(unsigned char bits)
	MOVFF	FSR2L, POSTDEC1
	MOVFF	FSR1L, FSR2L
	MOVFF	r0x00, POSTDEC1
	MOVFF	r0x01, POSTDEC1
	MOVFF	r0x02, POSTDEC1
	MOVFF	r0x03, POSTDEC1
	MOVLW	0x02
	MOVFF	PLUSW2, r0x00
	.line	190; hamming.c	for (mask = 0x01; mask < (0x01 << CODE_BITS); mask <<=1 )
	MOVLW	0x01
	MOVWF	r0x01
	CLRF	r0x02
_00107_DS_:
	MOVLW	0x80
	SUBWF	r0x01, W
	BC	_00110_DS_
	.line	192; hamming.c	if (bits & mask)
	MOVF	r0x01, W
	ANDWF	r0x00, W
	MOVWF	r0x03
	MOVF	r0x03, W
	BZ	_00109_DS_
	.line	194; hamming.c	sum++;
	INCF	r0x02, F
_00109_DS_:
	.line	190; hamming.c	for (mask = 0x01; mask < (0x01 << CODE_BITS); mask <<=1 )
	BCF	STATUS, 0
	RLCF	r0x01, F
	BRA	_00107_DS_
_00110_DS_:
	.line	198; hamming.c	return (sum & 0x01);
	MOVLW	0x01
	ANDWF	r0x02, F
	MOVF	r0x02, W
	MOVFF	PREINC1, r0x03
	MOVFF	PREINC1, r0x02
	MOVFF	PREINC1, r0x01
	MOVFF	PREINC1, r0x00
	MOVFF	PREINC1, FSR2L
	RETURN	

; ; Starting pCode block for Ival
	code
_g:
	DB	0x38, 0x54, 0x62, 0x71
; ; Starting pCode block for Ival
_gT:
	DB	0x07, 0x0b, 0x0d, 0x08, 0x04, 0x02, 0x01
; ; Starting pCode block for Ival
_hammingCodes:
	DB	0x00, 0x71, 0x62, 0x13, 0x54, 0x25, 0x36, 0x47, 0x38, 0x49, 0x5a, 0x2b
	DB	0x6c, 0x1d, 0x0e, 0x7f
; ; Starting pCode block for Ival
_h:
	DB	0x47, 0x2b, 0x1d
; ; Starting pCode block for Ival
_syndromeMask:
	DB	0x00, 0x10, 0x20, 0x08, 0x40, 0x04, 0x02, 0x01
; ; Starting pCode block for Ival
_hammingDecodeValues:
	DB	0x00, 0x00, 0x00, 0x03, 0x00, 0x05, 0x0e, 0x07, 0x00, 0x09, 0x0e, 0x0b
	DB	0x0e, 0x0d, 0x0e, 0x0e, 0x00, 0x03, 0x03, 0x03, 0x04, 0x0d, 0x06, 0x03
	DB	0x08, 0x0d, 0x0a, 0x03, 0x0d, 0x0d, 0x0e, 0x0d, 0x00, 0x05, 0x02, 0x0b
	DB	0x05, 0x05, 0x06, 0x05, 0x08, 0x0b, 0x0b, 0x0b, 0x0c, 0x05, 0x0e, 0x0b
	DB	0x08, 0x01, 0x06, 0x03, 0x06, 0x05, 0x06, 0x06, 0x08, 0x08, 0x08, 0x0b
	DB	0x08, 0x0d, 0x06, 0x0f, 0x00, 0x09, 0x02, 0x07, 0x04, 0x07, 0x07, 0x07
	DB	0x09, 0x09, 0x0a, 0x09, 0x0c, 0x09, 0x0e, 0x07, 0x04, 0x01, 0x0a, 0x03
	DB	0x04, 0x04, 0x04, 0x07, 0x0a, 0x09, 0x0a, 0x0a, 0x04, 0x0d, 0x0a, 0x0f
	DB	0x02, 0x01, 0x02, 0x02, 0x0c, 0x05, 0x02, 0x07, 0x0c, 0x09, 0x02, 0x0b
	DB	0x0c, 0x0c, 0x0c, 0x0f, 0x01, 0x01, 0x02, 0x01, 0x04, 0x01, 0x06, 0x0f
	DB	0x08, 0x01, 0x0a, 0x0f, 0x0c, 0x0f, 0x0f, 0x0f
; ; Starting pCode block for Ival
_hammingPackedDecodeValues:
	DB	0x00, 0x03, 0x05, 0xe7, 0x09, 0xeb, 0xed, 0xee, 0x03, 0x33, 0x4d, 0x63
	DB	0x8d, 0xa3, 0xdd, 0xed, 0x05, 0x2b, 0x55, 0x65, 0x8b, 0xbb, 0xc5, 0xeb
	DB	0x81, 0x63, 0x65, 0x66, 0x88, 0x8b, 0x8d, 0x6f, 0x09, 0x27, 0x47, 0x77
	DB	0x99, 0xa9, 0xc9, 0xe7, 0x41, 0xa3, 0x44, 0x47, 0xa9, 0xaa, 0x4d, 0xaf
	DB	0x21, 0x22, 0xc5, 0x27, 0xc9, 0x2b, 0xcc, 0xcf, 0x11, 0x21, 0x41, 0x6f
	DB	0x81, 0xaf, 0xcf, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	DB	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	DB	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	DB	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	DB	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	DB	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00


; Statistics:
; code size:	  750 (0x02ee) bytes ( 0.57%)
;           	  375 (0x0177) words
; udata size:	    0 (0x0000) bytes ( 0.00%)
; access size:	    6 (0x0006) bytes


	end
